<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--  引入vue.js  因为Element UI 依赖vue -->
    <script src="../static/js/vue.js"></script>
    <script src="../static/js/axios.js"></script>

    <link rel="stylesheet" href="../static/elementui/theme-chalk/index.css"/>
    <script src="../static/elementui/index.js"></script>
    <style type="text/css">
        #all{
            width:1500px;
            margin: 0 auto;
            margin-top: 55px;
        }
        #search_bar{
            height:160px;
            background-color:#eeeeee;
            text-align:center;
            line-height:80px;
            margin-top: 10px;
        }
        .star{
            color:red;
        }
        .div_out {
            margin-top: 15px;
        }
        .div_inner{
            position: relative;
            font-size: 14px;
            display: inline-block;
        }
        .content{
            width:500px;
            height:300px;
            border: 1px solid;
        }
        .span{
            display: inline-block;
            margin-left: 20px;
        }
    </style>
</head>
<body>
<div id="all">
    学员开课
    <el-divider></el-divider>
    <el-card class="box-card">
        <div id="search_bar">
            <div class="div_out">
                <div class="span">
                    <span class="star">*</span> 学员姓名：
                    <div class="div_inner">
                        <el-input v-model="stuName" id="studentName" placeholder="请输入关键字"></el-input>
                    </div>
                </div>
                <div class="span">
                    <span class="star">*</span> 手机号：
                    <div class="div_inner">
                        <el-input v-model="telephone" id="telephone" placeholder="请输入关键字"></el-input>
                    </div>
                </div>
                <div class="span">
                    <span class="star">*</span> 是否为线下学员：
                    <el-select v-model="offline" placeholder="请选择">
                        <el-option
                                v-for="item in offline_options"
                                :key="item.value"
                                :label="item.value"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </div>
                <div class="span">
                    <span class="star">*</span> 所属院校：
                    <div class="div_inner">
                        <template>
                            <el-select v-model="schoolList.id" clearable @change="selectTrigger(schoolList.id)" placeholder="请选择">
                                <el-option v-for="item in schoolList" :key="item.value" :label="item.schoolName"
                                           :value="item.id">
                                </el-option>
                            </el-select>
                        </template>
                    </div>
                </div>
                <br>
                <div class="span">
                    <el-button type="primary" size="small" @click="getAdminList">查询</el-button>
                </div>
                <div class="span">
                    <el-button type="primary" size="small" @click="reset">重置</el-button>
                </div>
            </div>
        </div>
        <template>
                <el-table
                        :data="tableData"
                        style="width: 100%"
                        :row-class-name="tableRowClassName">
                    <el-table-column type="index" label="序号" align="center" width="50">
                    </el-table-column>
                    <el-table-column prop="stuName" label="学员姓名" align="center" width="195">
                    </el-table-column>
                    <el-table-column prop="signInTime" label="注册时间" align="center" width="195" :formatter="formatDate">
                    </el-table-column>
                    <el-table-column prop="telephone" label="手机号" align="center" width="195">
                    </el-table-column>
                    <el-table-column prop="school.schoolName" label="归属学校" align="center" width="195">
                    </el-table-column>
                    <el-table-column prop="phase" label="学习阶段" align="center" width="195">
                    </el-table-column>
                    <el-table-column prop="offline" label="是否是线下学员" align="center" width="195">
                    </el-table-column>
                    <el-table-column fixed="right" prop="manager" label="操作" align="center" width="180">
                        <template slot-scope="scope">
                            <el-button @click="del(scope.row,scope.$index)" type="text"  size="small">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
        </template>
            <!-- 分页组件 -->
            <div class="block" style="margin-top: 20px;">
                <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                               :current-page="currentPage"
                               :page-sizes="[6, 12, 20]"
                               :page-size="6"
                               layout="total, sizes, prev, pager, next, jumper"
                               :total=total>
                </el-pagination>
            </div>
    </el-card>
</div>

<script>
    let vm = new Vue({
        el: "#all",
        data: {
            pageSize: 6,
            pageNum: 1,
            total: 0,
            dialogTableVisible: false,
            tableData: [],
            stuName:'',
            telephone:'',
            phase:'',
            schoolList: [],
            schoolId:'',
            offline_options: [{
                value: '是',
                label: '1'
            }, {
                value: '否',
                label: '2'
            }],
            offline:'',
        },
        created() {
            this.getAdminList();
            this.getSchoolList();
        },
        methods: {
            //时间格式化
            formatDate:function(row, column) {
                // 获取单元格数据
                let data = row[column.property]
                // if (this.$MyComm.isEmpty(data)) {
                // 	return ''
                // }
                let dt = new Date(data)
                return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
            },
            //
            handleClick(row) {
                console.log(row);
            },
            //监听每页条数改变
            handleSizeChange(val) {
                this.pageSize = val;
                this.getAdminList();
                console.log(`每页 ${val} 条`);
            },
            //监听当前页改变
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.pageNum = val;
                this.getAdminList();
            },
            getSchoolList() {
                axios.get("../school/findAll")
                    .then(res => {
                        console.log(res.data)
                        this.schoolList = res.data.data;
                    })
                    .catch(error => {
                        console.log(error)
                    })
            },
            getAdminList() {
                axios.get('../student/findClassList', {
                    params: {
                        pageSize: this.pageSize,
                        pageNum: this.pageNum,
                        stuName:this.stuName,
                        telephone: this.telephone,
                        schoolId:this.schoolId,
                        offline:this.offline
                    }
                })
                  /*  console.log(this.offline)*/
                    .then(res => {//此处一定要用 箭头函数  不然this 就不是this
                        console.log(res.data.data.data);
                        this.total = res.data.data.total;
                        this.tableData = res.data.data.data;
                    })
                    .catch(error => {
                        console.log(error);
                    });

            },
            selectTrigger(val) {
                this.schoolId = val;
              //  this.getAdminList();
            },
            reset() {
                this.stuName = ''
                this.telephone = ''
                this.offline = ''
            /*    this.schoolList.id = ''*/
                this.getAdminList();
            },
            del(row,index) { //删除
                this.$confirm('此操作将永久删除该学生, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        method: 'DELETE',
                        url: '../student/del/'+ row.id,
                    }).then(res =>{
                        if(res.data.code ===200 ){
                            //删除当前选中行
                            // console.log(vm.tableData);
                            vm.tableData.splice(index,1);
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }else{
                            this.$message({
                                message:res.data.message
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }

        }
    })
</script>

</body>
</html>